<template>
  <div>
    <!-- header区域 -->
    <div class="header">
      <div class="location" @click="location">{{area}}</div>
      <div id="allmap"></div>
      <van-search v-model="value" placeholder="请输入搜索关键词" class="search" @click="search" />
    </div>
    <!-- 轮播图 -->
    <van-swipe :autoplay="3000" class="swiper">
      <van-swipe-item class="pic" v-for="item in banner" :key="item.id">
        <img :src="item.image_url" />
      </van-swipe-item>
    </van-swipe>
    <!-- channel区域 -->
    <div class="channel">
      <router-link
        :to="`/home/nav?id=${item.id}`"
        class="box"
        v-for="item in channel"
        :key="item.id"
      >
        <img :src="item.icon_url" alt />
        <p>{{item.name}}</p>
      </router-link>
    </div>
    <!-- brand -->
    <div class="brand">
      <router-link to="/home/brand" class="title">品牌制造商直供</router-link>
      <router-link
        :to="`/home/brand/detail?id=${item.id}`"
        class="content-list"
        v-for="item in brandList"
        :key="item.id"
      >
        <div class="txt">
          <p>{{item.name}}</p>
          <p>{{item.floor_price}}元起</p>
        </div>
        <img :src="item.new_pic_url" alt />
      </router-link>
    </div>
    <!-- newgoods -->
    <div class="newgoods">
      <router-link :to="`/home/new?isNew`" class="newgoods-top">
        <div class="top">
          <p class="p1">新品首发</p>
          <p class="p2">查看全部</p>
        </div>
      </router-link>
      <div class="list">
        <ul>
          <router-link
            class="list-li"
            :to="{path: '/home/new/good',query:{id:item.id,openId:17516331686}}"
            v-for="item in newGoods"
            :key="item.id"
          >
            <img :src="item.list_pic_url" alt />
            <p class="p3">{{item.name}}</p>
            <p class="p4">{{item.goods_brief}}</p>
            <p class="p5">￥{{item.retail_price}}</p>
          </router-link>
        </ul>
      </div>
    </div>
    <!-- newgoods hotgoods -->
    <div class="newgoods hotgoods">
      <router-link :to="`/home/new?isHot`" class="newgoods-top">
        <div class="top">
          <p class="p6">
            人气推荐
            <span></span>
            好物精选
          </p>
          <p class="p7">查看全部</p>
        </div>
      </router-link>
      <div class="list">
        <ul>
          <router-link
            class="list-li"
            :to="`/home/new/good?id=${item.id}`"
            v-for="item in hotGoods"
            :key="item.id"
          >
            <img :src="item.list_pic_url" alt />
            <p class="p8">{{item.name}}</p>
            <p class="p9">{{item.goods_brief}}</p>
            <p class="p10">￥{{item.retail_price}}</p>
          </router-link>
        </ul>
      </div>
    </div>
    <!-- topiclist -->
    <div class="topiclist">
      <div class="topiclist-top">
        专题精选
        <span class="icon"></span>
      </div>
      <div class="list">
        <ul>
          <router-link
            :to="`/home/special?id=${item.id}`"
            v-for="item in topicList"
            :key="item.id"
            class="list-li"
          >
            <img :src="item.item_pic_url" alt />
            <div class="btom">
              <div class="box1">
                <p class="p11">{{item.title}}</p>
                <p class="p12">{{item.subtitle}}</p>
              </div>
              <div class="box2">{{item.price_info}}元起</div>
            </div>
          </router-link>
        </ul>
      </div>
    </div>
    <!-- newCategoryList -->
    <div class="newcategory">
      <div class="list" v-for="list in newCategoryList" :key="list.id">
        <div class="head">{{list.name}}好物</div>
        <div class="sublist">
          <router-link
            :to="`/home/new/good?id=${item.id}`"
            class="box"
            v-for="item in list.goodsList"
            :key="item.id"
          >
            <img :src="item.list_pic_url" alt />
            <p class="13">{{item.name}}</p>
            <p class="14">{{item.retail_price}}</p>
          </router-link>
          <router-link :to="`/home/nav?id=${list.id}`" class="box">
            <div class="last">
              <p>{{list.name}}好物</p>
              <span class="icon"></span>
            </div>
          </router-link>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations } from "vuex";
import { index } from "@/api/home";
export default {
  data() {
    return {
      area: "",
      value: "",
      banner: [],
      channel: [],
      brandList: [],
      newGoods: [],
      hotGoods: [],
      topicList: [],
      newCategoryList: []
    };
  },
  mounted() {
    // var _this = this;
    // var map = new BMap.Map("allmap"); // 创建Map实例
    // map.centerAndZoom(new BMap.Point(113.754407, 34.776794), 18); // 初始化地图,设置中心点坐标和地图级别
    // var geolocation = new BMap.Geolocation();
    // geolocation.getCurrentPosition(
    //   function(r) {
    //     if (this.getStatus() == BMAP_STATUS_SUCCESS) {
    //       console.log(r);
    //       _this.area = r.address.city;
    //       _this.setInfo(r);
    //     } else {
    //       alert("failed" + this.getStatus());
    //     }
    //   },
    //   { enableHighAccuracy: true }
    // );
  },
  created() {
    index().then(res => {
      // console.log(res);
      this.banner = res.banner;
      this.channel = res.channel;
      this.brandList = res.brandList;
      this.newGoods = res.newGoods;
      this.hotGoods = res.hotGoods;
      this.topicList = res.topicList;
      this.newCategoryList = res.newCategoryList;
    });
  },

  methods: {
    ...mapMutations(["setInfo"]),
    search() {
      this.$router.push("/search");
    },
    location() {
      this.$router.push("/home/city");
    }
  }
};
</script>

<style lang="scss" scoped>
.header {
  position: fixed;
  top: 0;
  z-index: 99;
  width: 100%;
  height: 1.173333rem;
  padding: 0 0.266667rem;
  background-color: #fff;
  .location {
    position: absolute;
    top: 50%;
    margin-top: -0.213333rem;
    width: 0.96rem;
    height: 0.426667rem;
    line-height: 0.426667rem;
    text-align: center;
  }
  .search {
    position: absolute;
    right: 0.533333rem;
    width: 8.506667rem;
    height: 1.173333rem;
  }
}
.swiper {
  width: 100%;
  height: 5.333333rem;
  // margin-top: 0.533333rem;
  .pic img {
    width: 100%;
    height: 5.333333rem;
  }
}
.channel {
  display: flex;
  justify-content: space-between;
  width: 100%;
  height: 2.453333rem;
  padding: 0.266667rem 0;
  background-color: #fff;
  box-sizing: border-box;
  .box {
    width: 2rem;
    height: 1.92rem;
    img {
      width: 0.773333rem;
      height: 0.773333rem;
    }
    p {
      width: 100%;
      height: 0.426667rem;
      margin: 0.32rem 0;
      line-height: 0.426667rem;
      text-align: center;
    }
  }
}
.brand {
  width: 100%;
  margin-top: 0.26667rem;
  background: #fff;
  .title {
    display: inline-block;
    width: 100%;
    height: 0.48rem;
    text-align: center;
    padding: 0.53333rem 0;
  }
  .content-list {
    float: left;
    width: 4.8rem;
    height: 3.13333rem;
    margin-left: 0.133333rem;
    margin-bottom: 0.266667rem;
    position: relative;
    display: block;
    .txt {
      position: absolute;
      top: 0;
      left: 0;
      padding: 0.13333rem;
      p {
        display: block;
      }
    }
    img {
      width: 100%;
      height: 100%;
    }
  }
}
.newgoods-top {
  margin-top: 0.26667rem;
  height: 3.46667rem;
  width: 100%;
  background: url("../../assets/images/bgnew.png") no-repeat;
  background-size: 100% 100%;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  .p1 {
    color: #8c9bae;
    font-size: 0.42667rem;
  }
  .p2 {
    width: 2.4rem;
    height: 0.66667rem;
    line-height: 0.66667rem;
    margin: 0.36rem auto 0 auto;
    font-size: 0.29333rem;
    background: #d8e4f0;
  }
}
.newgoods .list {
  margin-top: 0.26667rem;
  background: #fff;
  padding-bottom: 0.13333rem;
  ul {
    width: 100%;
    white-space: nowrap;
    overflow: auto;
    margin: 0;
    padding: 0;
    list-style: none;
    .list-li {
      display: inline-block;
      width: 3.73333rem;
      height: 3rem;
      margin: 0.06667rem 0 0.06667rem 0.33333rem;
      display: inline-block;

      img {
        width: 3.73333rem;
        height: 3.73333rem;
      }
      p {
        width: 94%;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        margin-top: 0.10667rem;
        text-indent: 1em;
        color: black;
      }
      .p3 {
        font-size: 0.4rem;
        font-weight: 700;
      }
      .p4 {
        color: #8a8a8a;
        font-size: 0.32rem;
      }
      .p5 {
        color: #9c3232;
        font-size: 0.32rem;
        text-align: left;
      }
    }
  }
}
.hotgoods .newgoods-top {
  margin-top: 0.26667rem;
  height: 3.46667rem;
  width: 100%;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  background: url("../../assets/images/bgtopic.png");
  background-size: 100% 100%;
  .top {
    text-align: center;
    .p6 {
      color: #b1a279;
      font-size: 0.42667rem;
      vertical-align: middle;
      span {
        width: 0.05333rem;
        height: 0.05333rem;
        font-size: 0.18667rem;
        display: inline-block;
        vertical-align: middle;
        background: #b1a279;
      }
    }
    .p7 {
      width: 2.4rem;
      height: 0.66667rem;
      line-height: 0.66667rem;
      margin: 0.36rem auto 0 auto;
      font-size: 0.29333rem;
    }
  }
}
.hotgoods .list {
  margin-top: 0.26667rem;
  background: #fff;
  padding-bottom: 0.13333rem;
  ul {
    width: 100%;
    white-space: nowrap;
    overflow: auto;
    margin: 0;
    padding: 0;
    list-style: none;
    .btom {
      display: flex;
      justify-content: space-between;
      margin-bottom: 2.666667rem;
      width: 100%;
      .list-li {
        width: 3.73333rem;
        height: 5.54667rem;
        margin: 0.06667rem 0 0.06667rem 0.33333rem;
        display: inline-block;
        img {
          width: 3.73333rem;
          height: 3.73333rem;
        }
        .p8 {
          font-size: 0.4rem;
          font-weight: 700;
          width: 94%;
        }
        .p9 {
          color: #8a8a8a;
          font-size: 0.32rem;
          text-align: left;
        }
        .p10 {
          color: #9c3232;
          font-size: 0.32rem;
          text-align: left;
        }
      }
    }
  }
}
.topiclist {
  margin-top: 0.26667rem;
  background: #fff;
  .topiclist-top {
    text-align: center;
    padding: 0.48rem;
    vertical-align: middle;
    .icon {
      display: inline-block;
      width: 0.42667rem;
      height: 0.42667rem;
      margin-left: 0.06667rem;
      background: url("../../assets/images/right.png") no-repeat;
      background-size: 100% 100%;
      vertical-align: middle;
    }
  }
  .list {
    white-space: nowrap;
    overflow: auto;
    ul {
      margin: 0;
      padding: 0;
      list-style: none;
      .list-li {
        display: inline-block;
        width: 7.66667rem;
        height: 6.666667rem;
        margin-left: 0.33333rem;
        img {
          display: block;
          width: 7.66667rem;
          height: 4.33333rem;
          border-radius: 0.13333rem;
        }
        .btom {
          display: flex;
          justify-content: space-between;
          width: 100%;
          .box1 {
            width: 90%;
            margin-top: 0.10667rem;
            .p11 {
              font-size: 0.4rem;
              font-weight: 700;
              text-align: left;
              color: black;
            }
            .p12 {
              width: 90%;
              color: #8a8a8a;
              font-size: 0.32rem;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
              text-align: left;
            }
          }
          .box2 {
            margin-top: 0.10667rem;
            color: #9c3232;
            font-size: 0.373333rem;
          }
        }
      }
    }
  }
}
.newcategory {
  margin-top: 0.26667rem;
  padding: 0 0.13333rem 0.33333rem 0.13333rem;
  .head {
    padding: 0.33333rem 0;
    text-align: center;
  }
  .sublist {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    width: 9.73333rem;
    margin: 0 auto;
    .box {
      width: 4.8rem;
      background: #fff;
      margin-bottom: 0.13333rem;
      padding-bottom: 0.13333rem;
      img {
        display: block;
        width: 4.02667rem;
        height: 4.02667rem;
        margin: 0 auto;
      }
      .p13 {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        width: 98%;
        margin-bottom: 0.06667rem;
        text-indent: 1em;
      }
      .p14 {
        color: #9c3232;
        margin-bottom: 0.06667rem;
        text-indent: 1em;
      }
    }
    .box {
      .last {
        width: 4.02667rem;
        height: 4.02667rem;
        margin: 0 auto;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        flex-wrap: wrap;
        p {
          height: 0.44rem;
          width: 100%;
          line-height: 0.44rem;
          color: #333;
          font-size: 0.44rem;
          text-align: center;
        }
        .icon {
          display: inline-block;
          width: 0.93333rem;
          height: 0.93333rem;
          background: url("../../assets/images/icon_go_more.png") no-repeat;
          background-size: 100% 100%;
          margin-top: 0.8rem;
        }
      }
    }
  }
}
</style>